<?php
session_start();

$url = "http://localhost:8080/moms-diary/services/signup";

$mail = $_REQUEST['mail'];
$password = $_REQUEST['password'];
$newpassword = $_REQUEST['newpassword'];
$gender = $_REQUEST['gender'];
$birthDate = $_REQUEST['birthDate'];
$mobileNo = $_REQUEST['mobileNo'];
$babyName = $_REQUEST['babyName'];
$babyBirthDate = $_REQUEST['babyBirthDate'];
$username = $_SESSION['username'];
$password = $_SESSION['password'];


$query = http_build_query(
		array(
				"password" => $password,
				"newpassword" => $newpassword,
				"birthDate" => $birthDate,
				"gender" => $gender,
				"mobileNo" => $mobileNo,
				"babyName" => $babyName,
				"babyBirthDate" => $babyBirthDate)
);

$ch = curl_init($url);
$auth = $username.":".$password;

curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $auth);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);

$data = curl_exec($ch);
$getinfo =  curl_getinfo($ch);

print_r($data);

if($getinfo["http_code"] == '202') {
	$_SESSION['login'] = md5($username.$newpassword);
	$_SESSION['password'] = $newpassword;
	header("Location: home.php");
	//kasih liat halaman kaya abis posting sesuatu di kaskus yang isinya berhasil posting terus di redirect ke halaman sebelumnya.
}
curl_close($ch);